<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Inv_uom_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    public function search_uom($uom_code, $uom_name){
      $sql;
          if($uom_code != "" && $uom_name != ""){
            $sql = "SELECT * FROM inv_uom WHERE uom_code LIKE ".$this->db->escape($uom_code)." AND uom_name LIKE '".$uom_name."' ";
          }else if($uom_code == "" && $uom_name != ""){
            $sql = "SELECT * FROM inv_uom WHERE uom_name LIKE ".$this->db->escape($uom_name)." ";
          }else{
            $sql = "SELECT * FROM inv_uom WHERE uom_code LIKE ".$this->db->escape($uom_code)." ";
          }
          //$query = $this->db->get_where('inv_uom', array('module_code' => $modulecode, 'module_name' => $modulename), 1);
          $query = $this->db->query($sql);
          if($query->num_rows() != 0){
            return $query->result();
          }
          else {
            $result = "No results found.";
            return $result;
          }
    }

    public function get_uom($id){
      $query = $this->db->select('*')
                        ->from('inv_uom')
                        ->where('uom_id',$id)
                        ->get();
      return $query->result(); 
    }

    public function edit_uom($data){
        $this->db->query("call inv_uom_dml(?,?,?,?,?,?,?,@id,@err,@msg)",$data);
        $que = $this->db->query("SELECT @err as error , @msg as msg");
        echo json_encode($que->result());
    }
    public function insert_uom($data){
        $this->db->query("call inv_uom_dml(?,?,?,?,?,?,?,@id,@err,@msg)",$data);
        $que = $this->db->query("SELECT @err as error , @msg as msg");
        echo json_encode($que->result());
    }
}